package com.cn.web;

import com.cn.entity.Goods;
import com.cn.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: chenyuncong
 * @Date: 2020/6/28 10:37
 */
@RestController
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 添加商品
     */
    @PostMapping("saveGoods")
    public void saveGoods(){
        Goods goods = new Goods();
        goods.setGoodsImg("xxx.jpg");
        goods.setGoodsName("刮须刀");
        goods.setGoodsPrice(99*100L);
        goods.setGoodsStock(100000);
        goods.setGoodsTitle("防水耐用电动刮须刀");
        goods.setCreateTime(System.currentTimeMillis());
        goods.setVersion(0);
        goodsService.save(goods);
    }

    /**
     * 开启商品购买
     */
    @PostMapping("startGoodsBuy")
    public void startGoodsBuy(Long id){
//        Goods g = goodsService.getById(id); //查询
        goodsService.startGoodsBuy(id);
    }
}
